﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;


namespace EvalServiceLibrary
{
    [DataContract]
    public class Eval
    {
        [DataMember]
        public string Submitter;
        [DataMember]
        public DateTime TimeSent;
        [DataMember]
        public string Comments;

        [DataMember] 
        public string Id;
    }

    [ServiceContract]
    public interface IEvalService
    {
        [OperationContract]
         void SubmitEval(Eval eval);
        
        [OperationContract]
        Eval GetEval(string id);

        [OperationContract]
        List<Eval> GetAllEvals();

        [OperationContract]
        List<Eval> GetEvalBySubmitter(string submitter);

        [OperationContract]

        void RemoveEval(string id);


    }



    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class EvalService : IEvalService
    {
        List<Eval> evals = new List<Eval>();
        int evalCount = 0;
        public void SubmitEval(Eval eval)
        {
            eval.Id = (++evalCount).ToString();
            evals.Add(eval);
            
        }

        public Eval GetEval(string id)
        {
            return evals.First(e => e.Id.Equals(id));
        }


        public List<Eval> GetAllEvals()
        {
            return evals;
        }

        public List<Eval> GetEvalBySubmitter(string submitter)
        {
            return evals.FindAll(e => e.Submitter.Equals(submitter));
        }

        public void RemoveEval(string id)
        {
            evals.Remove(evals.Find(e => e.Id.Equals(id)));
        }
    }
}
